package com.aiti.lulian.service.impl;


import cn.hutool.core.util.IdUtil;
import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.base.core.utils.message.Message;
import com.aiti.base.core.utils.uuid.UUIDUtil;
import com.aiti.lulian.constant.CardQuoteShareConstant;
import com.aiti.lulian.dto.CardBusinessQuotesDto;
import com.aiti.lulian.entity.CardQuoteShare;
import com.aiti.lulian.mapper.CardQuoteShareMapper;
import com.aiti.lulian.service.CardQuoteShareService;
import com.aiti.lulian.service.ICardBusinessQuotesService;
import com.aiti.lulian.vo.CardQuoteShareVo;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CardQuoteShareServiceImpl extends BaseSerivceImpl<CardQuoteShareMapper, CardQuoteShare> implements CardQuoteShareService {
    @Autowired
    private ICardBusinessQuotesService cardBusinessQuotesService;
    @Override
    public Message share(CardQuoteShareVo cardQuoteShareVo) {
        CardQuoteShare cardQuoteShare = new CardQuoteShare();
        BeanUtils.copyProperties(cardQuoteShareVo,cardQuoteShare);
        cardQuoteShare.setStatus(CardQuoteShareConstant.QUOTE_SHARE_RECEIVE_WAITING);
        String shareBaseId = UUIDUtil.getUUID();
        cardQuoteShare.setBaseId(shareBaseId);
        this.save(cardQuoteShare);
        CardBusinessQuotesDto cardBusinessQuotesDto = new CardBusinessQuotesDto();
        cardBusinessQuotesDto.setShareBaseId(shareBaseId);
        return Message.success(cardBusinessQuotesDto);
    }

    @Override
    public Message receive(CardQuoteShareVo cardQuoteShareVo) {
        LambdaUpdateWrapper<CardQuoteShare> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(CardQuoteShare::getStatus,CardQuoteShareConstant.QUOTE_SHARE_RECEIVED)
                .set(CardQuoteShare::getReceiverId,cardQuoteShareVo.getReceiverId())
                .set(CardQuoteShare::getReceiverEnterpriseId,cardQuoteShareVo.getReceiverEnterpriseId())
                .eq(CardQuoteShare::getBaseId,cardQuoteShareVo.getBaseId());
        this.update(wrapper);
        return Message.success();
    }
}
